﻿using System.Net;
using IT.CMS.Core;
using IT.CMS.Services.Sites;
using IT.CMS.Services.Tasks;

namespace IT.CMS.Services.Common
{
    /// <summary>
    /// Represents a task for keeping the site alive
    /// </summary>
    public partial class KeepAliveTask : ITask
    {
        private readonly ISiteContext _siteContext;

        public KeepAliveTask(ISiteContext siteContext)
        {
            this._siteContext = siteContext;
        }

        /// <summary>
        /// Executes a task
        /// </summary>
        public void Execute()
        {
            string url = _siteContext.CurrentSite.Url + "keepalive";
            using (var wc = new WebClient())
            {
                wc.DownloadString(url);
            }
        }
    }
}
